<% layout('/layouts/default.html', {title: '单项指标排名', libs: ['layout', 'dataGrid']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-tools pull-left" style="position: relative">
                <ul class="nav nav-tabs bangPing-tabs">
                    <li><a href="${ctx}/exam/dcSupExamRanking/unitRankingView?examId=${dcSupExamOrgScore.examId}">${text('评分排名')}</a></li>
                    <li class="active"><a href="${ctx}/exam/dcSupExamRanking/indexRankingView?examId=${dcSupExamOrgScore.examId}">${text('单项指标排名')}</a></li>
                </ul>
            </div>
            <#form:form id="searchForm" model="${dcSupExamOrgScore}" action="${ctx}/exam/dcSupExamRanking/indexListData" method="post" class="form-inline"
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
            <div style="float: right">
                <#form:hidden path="examId"/>
                <div class="form-group">
                    <button type="button" onclick="exportFile()"  class="btn btn-primary btn-sm">${text('导出')}</button>
                </div>
        </#form:form>
        </div>
    </div>
    <div class="box-body">
        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>
</div>
</div>

<div class="ui-layout-center">
    <div class="main-content">
        <form class="form-horizontal" id="inputForm2">
            <div class="box box-main">
                <div class="box-header">
                    <div class="box-title">
                        <i class="fa icon-chart"></i> ${text('单位评分信息')}
                    </div>
                    <div style="float: right" class="form-inline">
                        <div class="form-group">
                            <label class="control-label">${text('单位分类')}：</label>
                            <div class="control-inline width-160">
                                <#form:select path="groupUnit" dictType="dc_exam_unit_classification" blankOption="true" data-placeholder="请选择" class="form-control width-160" defaultValue="0"/>
                            </div>
                        </div>
                        <div class="form-group" style="margin-right: 20px;">
                            <label class="control-label">${text('排序')}：</label>
                            <div class="control-inline width-160">
                                <% var items = [{label:'默认排名',value:'0'},{label:'百分比排名',value:'1'},{label:'市直排名',value:'2'},{label:'区县排名',value:'3'}]; %>
                                <#form:select path="sortType" items="${items}"  blankOption="true" data-placeholder="请选择" itemLabel="label" itemValue="value" class="form-control width-120" defaultValue="0" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label">${text('单位')}：</label>
                            <div class="control-inline width-160">
                                <#form:treeselect   title="${text('单位')}" allowClear='true'
                                path="exameOrg" labelName="exameName" labelValue="${officeName!}" labelPath="taskLeaderOrgName"
                                url="${ctx}/quota/dcSupExamSumQuotaInfo/selectOrgs"
                                isReturnValue="false" allowClear="true" canSelectRoot="true" canSelectParent="true"
                                returnFullName="false" checkbox="true" chkboxType="{'Y':'','N':''}"
                                placeholder="请选择单位"/>
                            </div>
                        </div>
                        <div class="form-group" style="margin-left: 4px;">
                            <button type="button" class="btn btn-primary btn-sm" onclick="scoreSort()">${text('查询')}</button>
                            <button onclick="cz();" type="button" class="btn btn-default btn-sm">${text('重置')}</button>
                        </div>
                    </div>
                </div>
                <div class="ui-layout-content" id="dynamicTable">
                    <table id="dataGrid2"></table>
                </div>
            </div>
        </form>
    </div>
</div>
<% } %>
<script>
    let selectQuotaId;
    let selectData=[];
    //重置
    function cz(){
        $("#sortType").val('0').trigger("change");
        $("#exameOrgName").val('')
        $("#exameOrgCode").val('')
        $("#groupUnit").val('').trigger("change");
        scoreSort();
    }
    $('#dataGrid').dataGrid({
        dataGridPage: $('#dataGridPage'),
        searchForm: $("#searchForm"),
        autoGridHeight:function (){
            return 300;
        },
        showRownum: true,
        sortableColumn: false, // 列表不允许排序
        columnModel: [
            {header:'${text("主键")}',hidden: true, name:'id', index:'a.id', width:50, align:"left", frozen:true},
            {header:'${text("gradeOrg")}',hidden: true, name:'gradeOrg', width:50, align:"left", frozen:true},
            {header:'${text("任务Id")}',hidden: true, name:'examId', index:'a.id', width:50, align:"left", frozen:true},
            {header:'${text("指标Id")}',hidden: true, name:'quotaInfoId', index:'a.id', width:50, align:"left", frozen:true},
            {header:'${text("指标类别")}', name:'quotaType', index:'a.message_number', width:50, align:"left",formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('dc_quotaType')}, val, '${text("未知")}', true);}},
            {header:'${text("指标分类")}',hidden: true, name:'quotaClass',width:150, align:"left", frozen:true},
            {header:'${text("目标内容")}', name:'quotaContent', index:'a.task_title', width:150, align:"left"}
        ],
        onSelectRow: function(id, isSelect, event){
            changeGrid2Data(id,'0')
        },
        ajaxSuccess: function(data){
            if (data.list!=null && data.list.length>0){
                $("#dataGrid").jqGrid('setSelection',1);
            }
        }
    });
</script>


<script>
    let baseopt = {
        showRownum: true,
        datatype:"local",
        sortableColumn: false, // 列表不允许排序
        data:[],
        autoGridHeight: function(){return 'auto'},
        columnModel: [
            {header:'${text("主键")}',hidden: true, name:'id',width:150, align:"left", frozen:true},
            {header:'${text("默认排序")}', name:'orgSort', index:'a.login_code', width:200, align:"center",hidden: true},
            {header:'${text("单位分类")}', name:'groupUnit', width:100, align:"left",formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('dc_exam_unit_classification')}, val, '', true);}},
            {header:'${text("被考核单位名称")}', name:'exameOrgName', index:'a.user_name', width:200, align:"left"},
            {header:'得分百分比', name:'percentage', width:120,edittype:'text', align:"center",
                formatter: function(val, obj, row, act){
                    if (val==''||typeof val=="undefined"){val="0";}
                    if (val.toString().indexOf("%")!=-1){return val;}
                    return parseFloat(val).toFixed(2)+"%";
                }},
            {header:'${text("排名")}', name:'ranking', width:200, align:"center"}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){


        }
    }


    function changeGrid2Data(id,sortType) {
        let reqData=$('#dataGrid').dataGrid('getRowData', id);
        selectQuotaId=reqData.id;
        reqData.sortType=sortType;
        reqData.exameOrg=$("#exameOrgCode").val();
        reqData.groupUnit=$("#groupUnit").val();
        js.ajaxSubmit("${ctx}/exam/dcSupExamRanking/indexListScoreData", reqData, function (data){
            reloadGrid("dataGrid2",data)
        });
        $("#sortType").val(sortType).select2()
    }

    function reloadGrid(id,data){
        $("#gbox_" + id).remove();
        $("#dynamicTable").html('<table id="'+id+'"></table>');
        baseopt.data=data;
        selectData=data;
        $('#'+id).dataGrid(baseopt);
    }

    function exportFile(){
        window.open("${ctx}/exam/dcSupExamRanking/exportDxFile?examId="+$("#examId").val())
    }

    function scoreSort(){
        let sortType = $('#sortType').val();
        let selectId = $('#dataGrid').dataGrid('getSelectRow');
        changeGrid2Data(selectId,sortType);
    }
</script>

<script>

    $('#groupUnit').on('select2:select', function (evt) {
        // Do something
        $("#sortType").val('').trigger("change");
    });
    $("#sortType").on('select2:select',()=>{
        $('#groupUnit').val('').trigger("change");
    })
</script>